package com.bdq.common.utils;

import cn.hutool.extra.spring.SpringUtil;
import org.redisson.api.RedissonClient;

import java.util.concurrent.TimeUnit;

public class RedissonUtil {

    private static final RedissonClient redissonClient = SpringUtil.getBean(RedissonClient.class);

    /**
     * 加锁
     *
     * @param key
     * @param time
     */
    public static void lock(String key, long time) {
        redissonClient.getLock(key).lock(time, TimeUnit.SECONDS);
    }

    /**
     * 释放锁
     *
     * @param key
     */
    public static void unLock(String key) {
        redissonClient.getLock(key).unlock();
    }
}
